package com.steakliu.shardingsphere.jdbc.controller;

import com.steakliu.shardingsphere.jdbc.domain.user.User;
import com.steakliu.shardingsphere.jdbc.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 功能说明：
 * <p>
 * Original @Author: steakliu-刘牌, 2022-07-19  16:11
 * <p>
 * Copyright (C)2020-2022  steakliu All rights reserved.
 */
@RestController
public class UserController {

    @Autowired
    IUserService userService;

    final AtomicInteger count = new AtomicInteger(0);

    /**
     * read
     * @return
     */
    @GetMapping("/read")
    public List<User> read(){
        return userService.list();
    }

    @PostMapping("/write")
    public boolean write(@RequestBody User user){
        return userService.save(user);
    }

    @GetMapping("ra")
    public void ra(){
        int s = Math.abs(count.getAndIncrement()) % 3;
        System.out.println("value  "+s);
    }
}
